home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 9994 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.6 KB

  1. Path: lonestar.jpl.utsa.edu!nreitzel
  2. From: nreitzel@lonestar.jpl.utsa.edu (Norman L. Reitzel   )
  3. Newsgroups: comp.lang.c
  4. Subject: Re: #define "creating" strings ?
  5. Date: 14 Mar 1996 22:18:55 GMT
  6. Organization: University of Texas at San Antonio
  7. Message-ID: <4ia60f$dhq@ringer.cs.utsa.edu>
  8. References: <Do9tsI.H2t@undergrad.math.uwaterloo.ca>
  9. NNTP-Posting-Host: lonestar.jpl.utsa.edu
  10.  
  11. In article <Do9tsI.H2t@undergrad.math.uwaterloo.ca> crpalmer@solo.uwaterloo.ca (Chris Palmer) writes:
  12. >I have a problem that I would like to solve using a "feature" of the C
  13. >preprocessor that until now I've never seen or heard of.  A book that we have
  14. >here gives the example:
  15. >
  16. >#define MAKESTRING(x) "x"
  17. >
  18. >which does in fact produce strings that have the value of x substituted.
  19. >[eg: MAKESTRING(foo) gets processed into "foo"].
  20. >
  21. >I've verified this on a DEC Alpha (cc) and the GNU C compiler..
  22. >
  23. >Is this in fact a supported behaviour that should be portable to most
  24. >C compilers?
  25.  
  26. Sure.  Why is this surprizing?  The preprocessor performs character 
  27. string substitution, a la M4.  It doesn't care if it's assembling a 
  28. string with quotes or a syntactic disaster.
  29.  
  30. IMHO, this is an error prone practice, in a language that is ripe with 
  31. things that can be error prone.  Why would one want to substitute the
  32. expression MAKESTRING(nuts) for the equivalent and obvious syntax, "nuts" ?
  33.  
  34.  
  35.  
  36. -- 
  37.    Norman L. Reitzel, Jr.       |    "When you live beside the graveyard,
  38.    nreitzel@lonestar.utsa.edu   |     you can't cry for every funeral."
  39.    Blue Water Ventures, dba.    |                     Russian Proverb
  40.